﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using umbraco.NodeFactory;
using Vega.USiteBuilder;
using SPCFMedicineInformer.DocumentTypes;

namespace SPCFMedicineInformer.Helpers
{
    public class NodeParser
    {
        public static string ParseMedicine(string src)
        {
            if (!string.IsNullOrEmpty(src))
            {
                var sb = new StringBuilder();
                var sList = src.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                foreach (var nId in sList)
                {
                    int tempInt;
                    if (int.TryParse(nId, out tempInt))
                    {
                        Node node = new Node(tempInt);
                        var sNode = node.NodeTypeAlias == "MedicineItem" ? ContentHelper.GetByNodeId<MedicineItem>(tempInt) : null;
                        if (sNode != null)
                            sb.AppendLine(sNode.MedicineName + ",");
                    }
                }
                string result = sb.ToString();
                return StringUtils.RemoveLastSymbol(result,",");

            }
            return "";
        }


    }
}